package com.group9.controller;

import com.group9.dto.AddressInfo;
import com.group9.service.AddAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * Created by 45865 on 2020/5/29.
 */
@Controller
@RequestMapping("address")
public class AddressInfoController {
    @Autowired
    AddAddressService addAddressService;

    @RequestMapping(value = "add",method = RequestMethod.POST)
    @ResponseBody
    public String addressInfo(@RequestBody AddressInfo addressInfo, HttpSession session) {
        String loginName = (String) session.getAttribute("loginName");
        addressInfo.setLoginName(loginName);
        System.out.println(addressInfo);
        int rows = addAddressService.addAddress(addressInfo);
        if (rows == 1) {
            return "success";
        } else {
            return null;
        }
    }
}
